package com.scalar.forecast.forecastSetup.forms;

import com.scalar.forecast.forecastSetup.ForecastEntryField;
import com.scalar.forecast.forecastSetup.LevelBean;

import com.scalar.forecast.ForecastActionForm;

import java.util.ArrayList;

import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * User: Sujan Kumar
 * Date: Feb 7, 2005
 * Time: 5:16:29 PM
 */
public class ForecastSetupForm extends ForecastActionForm
{
    private boolean     byProduct;
    private boolean     byCustomer;
    private boolean     byOdm;
    private boolean     byProject;
    private String      tfName;
    private String      tfCompany;
    private ArrayList   levels;
    private ArrayList   forecastEntryFields;

    private String tfMeasureType;

    public ForecastSetupForm ( )
    {
        byProduct   = true; //by default it is selected
        byCustomer  = true; //by default it is selected
        byOdm       = false;
        byProject   = false;
        tfName      = "Month"; //by default time frame is by month.
        tfCompany   = "0";
        tfMeasureType = "";
        loadDefaultLevels( );
        loadDefaultEntryFields( );
    }

    public boolean isByCustomer() {
        return byCustomer;
    }

    public void setByCustomer(boolean byCustomer) {
        this.byCustomer = byCustomer;
    }

    public boolean isByOdm() {
        return byOdm;
    }

    public void setByOdm(boolean byOdm) {
        this.byOdm = byOdm;
    }

    public boolean isByProduct() {
        return byProduct;
    }

    public void setByProduct(boolean byProduct) {
        this.byProduct = byProduct;
    }

    public boolean isByProject() {
        return byProject;
    }

    public void setByProject(boolean byProject) {
        this.byProject = byProject;
    }

    public ArrayList getForecastEntryFields() {
        return forecastEntryFields;
    }

    public void setForecastEntryFields(ArrayList forecastEntryFields) {
        this.forecastEntryFields = forecastEntryFields;
    }

    public ArrayList getLevels() {
        return levels;
    }

    public void setLevels(ArrayList levels) {
        this.levels = levels;
    }

    public String getTfCompany() {
        return tfCompany;
    }

    public void setTfCompany(String tfCompany) {
        this.tfCompany = ( tfCompany == null ? null : tfCompany.trim() );
    }

    public String getTfName() {
        return tfName;
    }

    public void setTfName(String tfName) {
        this.tfName = ( tfName == null ? null : tfName.trim() );
    }

    private void loadDefaultLevels()
    {
        levels = new ArrayList();
        levels.add ( new LevelBean ( "Sales Person Forecast", "1", true ) );
        levels.add ( new LevelBean ( "Regional Forecast", "2", false ) );
        levels.add ( new LevelBean ( "Country Level Forecast", "3", false ) );
        levels.add ( new LevelBean ( "VP of Sales", "4", false ) );
    }
    private void loadDefaultEntryFields( )
    {
        forecastEntryFields = new ArrayList();
        forecastEntryFields.add ( new ForecastEntryField ( "Qty", true ) );
        forecastEntryFields.add ( new ForecastEntryField ( "Price", true ) );
        forecastEntryFields.add ( new ForecastEntryField ( "Confidence Level", false ) );
    }

    public String getTfMeasureType()
    {
        return tfMeasureType;
    }

    public void setTfMeasureType( String tfMeasureType )
    {
        this.tfMeasureType = ( tfMeasureType == null ? null : tfMeasureType.trim() );
    }

    public void reset( ActionMapping actionMapping, HttpServletRequest httpServletRequest )
    {
        byProduct   = true; //by default and its must be selected
        byCustomer  = false;
        byOdm       = false;
        byProject   = false;
        tfName      = "Month"; //by default time frame is by month.
        tfCompany   = "0";
        tfMeasureType = "";
        if ( levels != null )
        {
            int levelCnt = levels.size();
            LevelBean levelBean = null;
            for ( int i=0; i < levelCnt; i++ )
            {
                levelBean = ( LevelBean )levels.get( i );
                levelBean.setSelected( false );
            }
        }
        if ( forecastEntryFields != null )
        {
            int entryFieldsCnt = forecastEntryFields.size();
            ForecastEntryField forecastEntryField = null;
            for ( int i=0; i < entryFieldsCnt; i++ )
            {
                forecastEntryField = ( ForecastEntryField )forecastEntryFields.get( i );
                forecastEntryField.setEntrySelected( false );
            }
        }
    }
}
